<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>parent && root</h2>
      <child></child>
    </div>

    <script src="./lib/Vue3.js"></script>
    <script>
      const { createApp } = Vue;

      // 可以在子组件里面通过this.$parent属性直接拿到父组件的实例
      // 可以在任意组件里面用过this.$root属性获取到根组件的实例

      // this.$parent和this.$root是没有响应式
      const Child = {
        template: `
          <div>child子组件</div>
        `,
        beforeCreate() {
          console.log("son create");
        },
        mounted() {
          console.log(this.$parent.count);
          console.log(this.$parent.fn);

          console.log(this.$root.count);
        },
      };

      createApp({
        data() {
          return {
            count: 10,
          };
        },
        methods: {
          fn() {},
        },
        components: {
          Child,
        },
        beforeCreate() {
          console.log("father create");
        },
        mounted() {
          console.log(this);
        },
      }).mount("#app");
    </script>
  </body>
</html>
